#include "GameBoard.h"

namespace TUMAR { namespace CountryRoads {
	Tile::Tile(void) : type(Empty), Orientation(0)
	{
	}

	Tile::Tile(const Tile& copy) : type(copy.type)
	{
		this->Position[0] = copy.Position[0];
		this->Position[1] = copy.Position[1];
		this->Orientation = copy.Orientation;
	}
	
	Tile::~Tile(void)
	{
	}

	TileType Tile::GetType(void) const
	{
		return this->type;
	}

	void Tile::SetType(TileType type)
	{
		if(this->type != Empty)
		{
			throw new std::exception("Can't change type of tile twice!");
		}

		this->type = type;
	}

	void Tile::Reset(void)
	{
		this->type = Empty;
	}

	UserTile::UserTile(void)
	{
	}
	
	UserTile::~UserTile(void)
	{
	}

	Character::Character(void)
	{
	}
	
	Character::~Character(void)
	{
	}

	void Character::initPosition(int x, int y, int orientation)
	{
		this->Position[0]=x;
		this->Position[1]=y;
		this->Orientation=orientation;
	}

	void Character::changePosition(bool x, bool up, int orientation)
	{
		int i=x ? 0 : 1;
		this->Position[i]=up? Position[i]++ : Position[i]--;
		this->Orientation=orientation;
	}
	
	GameBoard::GameBoard(int width, int height) : width(width), height(height), StartTile(NULL), EndTile(NULL), UserTiles()
	{
		this->Character = new TUMAR::CountryRoads::Character();
		for(int y = 0; y < height; y++)
		{
			for(int x = 0; x < width; x++)
			{
				Tile tile;
				tile.Position[0] = x;
				tile.Position[1] = y;

				tiles.push_back(tile);
			}
		}
	}
	
	GameBoard::~GameBoard(void)
	{
		delete this->Character;
	}

	void GameBoard::Reset(void)
	{
		for(std::vector<Tile>::iterator it = this->tiles.begin(); it != this->tiles.end(); it++)
		{
			it->Reset();
		}
	}
	
	int GameBoard::GetWidth(void) const
	{
		return this->width;
	}

	int GameBoard::GetHeight(void) const
	{
		return this->height;
	}

	Tile* GameBoard::GetTile(int x, int y)
	{
		return &tiles.at(y * width + x);
	}

	const Tile* GameBoard::GetTile(int x, int y) const
	{
		return &tiles.at(y * width + x);
	}

	//Character* GameBoard::GetCharacter(void)
	//{
	//	return this->Character;
	//}

	//const Character* GameBoard::GetCharacter(void) const
	//{
	//	return this->Character;
	//}
}}